<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>知识库管理 - 医院智能客服系统</title>
    <style>
        body {
            font-family: 'Microsoft YaHei', sans-serif;
            margin: 0;
            padding: 0;
            background-color: #f5f5f5;
            color: #333;
        }
        .container {
            max-width: 1000px;
            margin: 0 auto;
            padding: 20px;
        }
        header {
            background-color: #1e88e5;
            color: white;
            padding: 20px;
            text-align: center;
            border-radius: 5px 5px 0 0;
        }
        .nav {
            display: flex;
            margin-bottom: 20px;
            background-color: white;
            border-radius: 5px;
            box-shadow: 0 2px 5px rgba(0,0,0,0.1);
        }
        .nav a {
            padding: 15px 20px;
            text-decoration: none;
            color: #333;
            font-weight: bold;
        }
        .nav a:hover {
            background-color: #f1f1f1;
        }
        .nav a.active {
            background-color: #1e88e5;
            color: white;
        }
        .info-card {
            background-color: white;
            padding: 20px;
            margin-bottom: 20px;
            border-radius: 5px;
            box-shadow: 0 2px 5px rgba(0,0,0,0.1);
        }
        table {
            width: 100%;
            border-collapse: collapse;
            margin-bottom: 20px;
        }
        th, td {
            padding: 12px 15px;
            text-align: left;
            border-bottom: 1px solid #ddd;
        }
        th {
            background-color: #1e88e5;
            color: white;
        }
        tr:hover {
            background-color: #f5f5f5;
        }
        form {
            display: flex;
            flex-direction: column;
        }
        .form-group {
            margin-bottom: 15px;
        }
        label {
            font-weight: bold;
            margin-bottom: 5px;
            display: block;
        }
        input[type="text"],
        textarea {
            width: 100%;
            padding: 10px;
            border: 1px solid #ddd;
            border-radius: 5px;
            font-size: 14px;
        }
        button {
            padding: 10px 20px;
            background-color: #1e88e5;
            color: white;
            border: none;
            border-radius: 5px;
            cursor: pointer;
            font-size: 14px;
        }
        button:hover {
            background-color: #1976d2;
        }
        .btn-danger {
            background-color: #d32f2f;
        }
        .btn-danger:hover {
            background-color: #c62828;
        }
    </style>
</head>
<body>
    <div class="container">
        <header>
            <h1>知识库管理</h1>
        </header>

        <div class="nav">
            <a href="/">智能问答</a>
            <a href="/departments">科室信息</a>
            <a href="/doctors">医生信息</a>
            <a href="/knowledge" class="active">知识库管理</a>
            <a href="/records">咨询记录</a>
        </div>

        <div class="info-card">
            <h2>添加新知识</h2>
            <form action="/add_knowledge" method="POST">
                <div class="form-group">
                    <label for="question">问题:</label>
                    <input type="text" id="question" name="question" required>
                </div>
                <div class="form-group">
                    <label for="answer">答案:</label>
                    <textarea id="answer" name="answer" rows="4" required></textarea>
                </div>
                <div class="form-group">
                    <label for="category">分类:</label>
                    <input type="text" id="category" name="category" required>
                </div>
                <button type="submit" class="btn">添加</button>
            </form>
        </div>

        <div class="info-card">
            <h2>知识库列表</h2>
            <table>
                <thead>
                    <tr>
                        <th>ID</th>
                        <th>问题</th>
                        <th>答案</th>
                        <th>分类</th>
                        <th>操作</th>
                    </tr>
                </thead>
                <tbody>
                    {% for item in knowledge_items %}
                    <tr>
                        <td>{{ item[0] }}</td>
                        <td>{{ item[1] }}</td>
                        <td>{{ item[2] }}</td>
                        <td>{{ item[3] }}</td>
                        <td>
                            <a href="/delete_knowledge/{{ item[0] }}" class="btn btn-danger">删除</a>
                        </td>
                    </tr>
                    {% endfor %}
                </tbody>
            </table>
        </div>
    </div>
</body>
</html>